package kyuu.acshmily.net
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import kyuu.acshmily.events.LoaderEvent;

	[Event(name="loadComplete", type="kyuu.acshmily.events.LoaderEvent")]

	/**
	 * 关键词列表加载器
	 */
	public class RiverCrabLoader extends EventDispatcher
	{
		private static const filterFile:String = "./player/forbidden.xml";
		private var loader:URLLoader = null;

		public function RiverCrabLoader(){}

		public function load():void{
			try{
				loader = new URLLoader();
				loader.addEventListener(Event.COMPLETE, completeHandler);
				
				var request:URLRequest = new URLRequest(filterFile);
				loader.load(request);
			}
			catch(err:Error){}
		}

		public function close():void{
			if(loader == null) return;

			loader.removeEventListener(Event.COMPLETE, completeHandler);
			loader.close();
			loader = null;
		}

		private function completeHandler(e:Event):void{
			var xml:Object = loader.data;
			var le:LoaderEvent = new LoaderEvent(LoaderEvent.LOAD_COMPLETE, false, false, xml);
			dispatchEvent(le);
		}
	}
}